<?php
namespace app\controller;

use app\BaseController;
use app\Request;
use common\service\WechatService;
use think\App;
use think\cache\driver\Redis;
use think\Exception;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Log;
use think\Queue;

class Wechat extends BaseController
{

    private $wechatConfig;
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->wechatConfig = config('wechat');

    }

    /**
     * 微信App登陆接口
     * @return \json
     */
    public function wechatLogin()
    {
        $code = \think\facade\Request::get('code');
        $wechat_token_callback = WechatService::get_token($this->wechatConfig,$code);
        if(false == $wechat_token_callback || isset($wechat_token_callback['errcode'])){
           return error('请求出错，获取token出错',$wechat_token_callback['errmsg']);
        }
        $wechat_user_callback = WechatService::get_user_info($this->wechatConfig,$wechat_token_callback['access_token'],$wechat_token_callback['openid']);
        if(false == $wechat_user_callback || isset($wechat_user_callback['errcode'])){
            return error("请求出错，获取用户信息失败");
        }

        //$wechat_user_callback  获取的为用户信息
    }


}
